package com.breaker.kata.leetcode;

import com.breaker.kata.leetcode.domain.ListNode;

public class DeleteDuplicatesListNode {

    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return null;
        }
        return new ListNode(head.val, createNextNode(head.val, head.next));
    }

    private ListNode createNextNode(int parentVal, ListNode next) {
        if (next == null) {
            return null;
        }
        if (parentVal == next.val) {
            return createNextNode(next.val, next.next);
        }
        return new ListNode(next.val, createNextNode(next.val, next.next));
    }
}